from selenium.webdriver.common.by import By

from pom.base import BaseDriver

class AdminBankManage(BaseDriver):
    def __init__(self, driver):
        super(AdminBankManage, self).__init__(driver)

    # 题库管理
    _bank_manage = By.XPATH, '//span[text()="题库管理"]'

    # 实训题库
    _training_bank = By.XPATH, '//li[text()="实训题库"]'

    # 竞赛题库
    _competation_bank = By.XPATH, '//li[text()="竞赛题库"]'

    #新增按钮
    _add_bank_btn = By.XPATH, '//button//span[text()="新增"]'

    # 板块下拉框
    _plate = By.XPATH, '//div[@class="search f-tar f-fs-14"]/div[@class="el-select f-m-r-20 el-select--small"][1]//span[@class="el-input__suffix-inner"]'

    # 初级
    _primary = By.XPATH, '//div[@class="el-select-dropdown el-popper"][1]//span[text()="初级"]'

    # 中级
    _medium = By.XPATH, '//div[@class="el-select-dropdown el-popper"][1]//span[text()="中级"]'

    # 高级
    _senior = By.XPATH, '//div[@class="el-select-dropdown el-popper"][1]//span[text()="高级"]'

    # 真题
    _forCompa = By.XPATH, '//div[@class="el-select-dropdown el-popper"][1]//span[text()="真题"]'

    # 状态下拉框
    _status = By.XPATH, '//div[@class="search f-tar f-fs-14"]/div[@class="el-select f-m-r-20 el-select--small"][2]//span[@class="el-input__suffix-inner"]'

    # 未发布
    _notPubish = By.XPATH, '//li//span[text()="未发布"]'

    # 已发布
    _publish = By.XPATH, '//li//span[text()="已发布"]'

    # 搜索框
    _search_box = By.XPATH, '//input[@placeholder="请输入搜索内容"]'

    # 搜索按钮
    _search_btn = By.XPATH, '//span[text()="搜索"]'

    # 导入题库按钮
    _import_btn = By.XPATH, '//button//span[text()="导入"]'

    # 更新时间排序
    _update_time_asc_sort = By.XPATH, '//div[text()="更新时间"]//i[@class="sort-caret ascending"]'

    _update_time_desc_sort = By.XPATH, '//div[text()="更新时间"]//i[@class="sort-caret descending"]'

    # 发布时间排序
    _publish_time_asc_sort = By.XPATH, '//div[text()="发布时间"]//i[@class="sort-caret ascending"]'

    _publish_time_desc_sort = By.XPATH, '//div[text()="发布时间"]//i[@class="sort-caret descending"]'

    # 下一页
    _page_right = By.XPATH, '//i[@class="el-icon el-icon-arrow-right"]'

    # 上一页
    _page_left = By.XPATH, '//i[@class="el-icon el-icon-arrow-left"]'

    # 页面返回总条数
    _total_num = By.XPATH, '//span[@class="el-pagination__total"]'

    """
    添加实训题库的元素
    """
    # 所属模块下拉框
    _create_plate = By.XPATH, '//input[@placeholder="请选择所属模块"]'

    # 初级
    _create_primary = By.XPATH, '//body/div[@class="el-select-dropdown el-popper"]//ul//li//span[text()="初级"]'

    # 中级
    _create_medium = By.XPATH, '//body/div[@class="el-select-dropdown el-popper"]//ul//li//span[text()="中级"]'

    # 高级
    _create_senior = By.XPATH, '//body/div[@class="el-select-dropdown el-popper"]//ul//li//span[text()="高级"]'

    # 套题标题
    _paper_title = By.XPATH, '//input[@placeholder="请输入套题标题"]'

    # 简介
    _decs = By.XPATH, '//input[@placeholder="请输入简介"]'

    # 镜像关联 是
    _connect_image = By.XPATH, '//span[text()="是"]'

    # 镜像关联 否
    _not_connect_image = By.XPATH, '//span[text()="否"]'

    # 答题模式
    _answer_model = By.XPATH, '//input[@placeholder="请选择答题模式"]'

    # 简易模式
    _easy_model = By.XPATH, '//span[text()="简易模式"]'

    # 困难模式
    _hard_model = By.XPATH, '//span[text()="困难模式"]'

    # 其他说明
    _other_desc = By.XPATH, '//input[@placeholder="请输入其他说明"]'

    # 上传附件
    _upload_file = By.XPATH, '//div[@aria-label="添加套题"]//input[@name="file"]'

    # 取消按钮
    _cancel_btn = By.XPATH, '//span[text()="取消"]'

    # 确定按钮
    _confirm_btn = By.XPATH, '//span[text()="确定"]'

    # 搜索结果的所有结果
    _result_list = By.XPATH, '//tbody//tr'


    """
     搜索结果列表

     """

    # 返回搜索后的列表数量
    @property
    def search_result_list(self):
        eles = self.find_eles(*self._result_list)
        return eles

    # 返回数据有几个标签
    def bank_list_data_num(self, line, col):
        tmp = By.XPATH, r'//tbody//tr[{}]/td[{}]//span/span'.format(line, col)
        eles = self.find_eles(*tmp)
        return eles

    # 返回第 line 行的 第 col 列的元素
    def mul_bank_list_data_ele(self, line, col, num=1):
        tmp = By.XPATH, r'//tbody//tr[{}]/td[{}]//span/span[{}]'.format(line, col, num)
        ele = self.find_ele(*tmp)
        return ele

    def bank_list_data_ele(self, line, col):
        tmp = By.XPATH, r'//tbody//tr[{}]/td[{}]//span'.format(line, col)
        ele = self.find_ele(*tmp)
        return ele

    @property
    def create_senior(self):
        ele = self.find_ele(*self._create_senior)
        self.logger.info("添加实训套题 [高级] 模块")
        return ele

    @property
    def create_mudeium(self):
        ele = self.find_ele(*self._create_medium)
        self.logger.info("添加实训套题 [中级] 模块")
        return ele

    @property
    def create_primary(self):
        ele = self.find_ele(*self._create_primary)
        self.logger.info("添加实训套题 [初级] 模块")
        return ele


    @property
    def confirm_btn(self):
        ele = self.find_ele(*self._confirm_btn)
        self.logger.info("添加实训套题 [确定] 按钮")
        return ele

    @property
    def cancel_btn(self):
        ele = self.find_ele(*self._cancel_btn)
        self.logger.info("添加实训套题 [取消] 按钮")
        return ele

    @property
    def upload_file(self):
        ele = self.find_ele(*self._upload_file)
        self.logger.info("添加实训套题 [上传附件] 按钮")
        return ele

    @property
    def other_desc(self):
        ele = self.find_ele(*self._other_desc)
        self.logger.info("添加实训套题 [其他说明] 输入框")
        return ele

    @property
    def easy_model(self):
        ele = self.find_ele(*self._easy_model)
        self.logger.info("添加实训套题 选择 [简易模式]")
        return ele

    @property
    def hard_model(self):
        ele = self.find_ele(*self._hard_model)
        self.logger.info("添加实训套题 选择[困难模式]")
        return ele

    @property
    def answer_model(self):
        ele = self.find_ele(*self._answer_model)
        self.logger.info("添加实训套题 [答题模式] 下拉框")
        return ele

    @property
    def not_connect_image(self):
        ele = self.find_ele(*self._not_connect_image)
        self.logger.info("添加实训套题 关联镜像 [否] 复选框")
        return ele

    @property
    def connect_image(self):
        ele = self.find_ele(*self._connect_image)
        self.logger.info("添加实训套题 关联镜像 [是] 复选框")
        return ele

    @property
    def desc(self):
        ele = self.find_ele(*self._decs)
        self.logger.info("添加实训套题 [简介] 输入框")
        return ele

    @property
    def paper_title(self):
        ele = self.find_ele(*self._paper_title)
        self.logger.info("添加实训套题 [标题] 输入框")
        return ele

    @property
    def create_plate(self):
        ele = self.find_ele(*self._create_plate)
        self.logger.info("添加实训套题 [所属模块] 下拉框")
        return ele

    @property
    def bank_manage(self):
        ele = self.find_ele(*self._bank_manage)
        self.logger.info(" [题库管理] 菜单栏")
        return ele

    @property
    def training_bank(self):
        ele = self.find_ele(*self._training_bank)
        self.logger.info(" [实训题库] 菜单栏")
        return ele

    @property
    def competation_bank(self):
        ele = self.find_ele(*self._competation_bank)
        self.logger.info(" [竞赛题库] 菜单栏")
        return ele

    @property
    def  add_bank_btn(self):
        ele = self.find_ele(*self._add_bank_btn)
        self.logger.info(" [添加实训题库] 按钮")
        return ele

    @property
    def plate(self):
        ele = self.find_ele(*self._plate)
        self.logger.info(" [模块] 下拉框")
        return ele

    @property
    def primary(self):
        ele = self.find_ele(*self._primary)
        self.logger.info(" [初级] 模块")
        return ele

    @property
    def medium(self):
        ele = self.find_ele(*self._medium)
        self.logger.info(" [中级] 模块")
        return ele

    @property
    def senior(self):
        ele = self.find_ele(*self._senior)
        self.logger.info(" [高级] 模块")
        return ele

    @property
    def forCompa(self):
        ele = self.find_ele(*self._forCompa)
        self.logger.info(" [真题] 模块")
        return ele

    @property
    def status(self):
        ele = self.find_ele(*self._status)
        self.logger.info(" [状态] 下拉框")
        return ele

    @property
    def notPublish(self):
        ele = self.find_ele(*self._notPubish)
        self.logger.info(" [未发布] 状态")
        return ele

    @property
    def pulish(self):
        ele = self.find_ele(*self._publish)
        self.logger.info(" [已发布] 状态")
        return ele

    @property
    def search_box(self):
        ele = self.find_ele(*self._search_box)
        self.logger.info(" [搜索] 输入框")
        return ele

    @property
    def search_btn(self):
        ele = self.find_ele(*self._search_btn)
        self.logger.info(" [搜索] 按钮")
        return ele

    @property
    def import_btn(self):
        ele = self.find_ele(*self._import_btn)
        self.logger.info(" [导入题库] 按钮")
        return ele


    # 发布时间排序

    @property
    def update_time_asc_sort(self):
        ele = self.find_ele(*self._update_time_asc_sort)
        self.logger.info("根据更新时间升序排序")
        return ele

    @property
    def update_time_desc_sort(self):
        ele = self.find_ele(*self._update_time_desc_sort)
        self.logger.info("根据更新时间降序排序")
        return ele

    @property
    def publish_time_asc_sort(self):
        ele = self.find_ele(*self._publish_time_asc_sort)
        self.logger.info("根据发布时间升序排序")
        return ele

    @property
    def publish_time_desc_sort(self):
        ele = self.find_ele(*self._publish_time_desc_sort)
        self.logger.info("根据发布时间降序排序")
        return ele

    @property
    def page_right(self):
        ele = self.find_ele(*self._page_right)
        return ele

    @property
    def page_left(self):
        ele = self.find_ele(*self._page_left)
        return ele

    @property
    def total_num(self):
        ele = self.find_ele(*self._total_num)
        self.logger.info("页面返回的所有数据条数")
        return ele

